﻿#include "stdafx.h"

#include "svgcanvasinfowidget.h"

#include "svgcanvas.h"
#include "widgets/svgpropinput.h"
#include "widgets/svgcolorselector.h"

#include <QLabel>

SvgCanvasInfoWidget::SvgCanvasInfoWidget(QWidget* parent)
	: QWidget(parent)
	, m_widthInput(new SvgPropInput(tr("Width"), 1000000, 0, this))
	, m_heightInput(new SvgPropInput(tr("Height"), 1000000, 0, this))
	, m_colorSelector(new SvgColorSelector(this))
{
	const auto label = new QLabel(tr("Canvas: "), this);

	connect(m_widthInput, &SvgPropInput::ValueChanged, this, &SvgCanvasInfoWidget::_CanvasSizeChanged);
	connect(m_heightInput, &SvgPropInput::ValueChanged, this, &SvgCanvasInfoWidget::_CanvasSizeChanged);
	connect(m_colorSelector, &SvgColorSelector::ColorSelected, this, &SvgCanvasInfoWidget::CanvasBackgroundChanged);

	label->setGeometry(0, 0, 150, 30);
	m_widthInput->setGeometry(0, 30, 80, 80);
	m_heightInput->setGeometry(100, 30, 80, 80);
	m_colorSelector->setGeometry(0, 130, 80, 80);
}

void SvgCanvasInfoWidget::UpdateData(const SvgCanvas& canvas) const
{
	m_widthInput->SetValue(canvas.Width());
	m_heightInput->SetValue(canvas.Height());
	m_colorSelector->SetColor(canvas.Background());
}

void SvgCanvasInfoWidget::_CanvasSizeChanged(double)
{
	emit CanvasSizeChanged(m_widthInput->Value(), m_heightInput->Value());
}

